# -*- coding: utf-8 -*-

import os,sys

if sys.version[0] == '2':
    print('\n此脚本仅运行在python3环境, 请安装最新版QPython并切换到python3环境')
    sys.exit()

runfile = os.environ['HOME'] + '/bin/qpython3-android5.sh'

if 'termux' in runfile:
    print('\n你已在termux的python环境中')
    sys.exit()

with open(runfile, 'r') as f:
    text = f.read()

text = text.replace('. $DIR/init.sh && $DIR/python3-android5 "$@"', 'echo $AP_PORT > /sdcard/qpython/AP_PORT&&echo $AP_HANDSHAKE > /sdcard/qpython/AP_HANDSHAKE&&$DIR/ssh -p8022 -i /sdcard/qpython/id_rsa -t localhost "cd /sdcard/qpython&&python $@"')


with open(runfile, 'w') as f:
    f.write(text)

print('\n1. 配置完成，在编辑器界面点击运行已切换到termux的python环境')
print('\n2. 请在termux安装python并运行命令完成termux的初次配置: python bear.py')
print('\n3. 在设置里来回切换python环境，即可恢复默认设置')